// register
// login

const registerForm=document.querySelector('.register form')
const loginForm=document.querySelector('.login form')
const registerA=registerForm.querySelector('.register a')
const loginA=loginForm.querySelector('.login a')
registerA.addEventListener('click',()=>{
    document.querySelector('.register').style.display='none'
    document.querySelector('.login').style.display='block'
})
loginA.addEventListener('click',()=>{
    document.querySelector('.register').style.display='block'
    document.querySelector('.login').style.display='none'
})
registerForm.addEventListener('submit',async function(e){
    e.preventDefault()
    const data=serialize(registerForm,{hash:true,empty:true})
    const res=await axios({
        url:'/api/register',
        method:'post',
        data,
    })
    if (res.data.code==0) {
        toastr.success(res.data.message)
        registerForm.reset()
        registerA.click()
    }
})
loginForm.addEventListener('submit',async function(e){
    e.preventDefault()
    const data=serialize(loginForm,{hash:true,empty:true})
    const res=await axios({
        url:'api/login',
        method:'post',
        data,
    })
    if (res.data.code==0) {
        toastr.success(res.data.message)
        // console.log(res);
        localStorage.setItem('cms90',res.data.token)
        setTimeout(()=>location.href='/index.html',1000)
    }
})